import { AdminData, AdminResult } from "@/types/admin";
import { PageParams, PageResult } from "@/types/common";
import { LoginResult } from "@/types/employee";
import request from "@/utils/request";

/**
 * 登录
 * @param data body参数
 * @returns 
 */
export const postAdminLoginAPI = (params: {
  username: string
  password: string
}) => {
  return request<LoginResult>({
    method: 'POST',
    url: '/admin/login',
    data: params
  })
}
/**
 * 退出
 * @returns 
 */
export const postAdminLogoutAPI = () => {
  return request({
    method: 'POST',
    url: '/admin/logout'
  })
}
/**
 * 分页查询  query参数
 * @param data 
 * @returns 
 */
export const getAdminPageAPI = (params: PageParams & { name?: string }) => {
  return request<PageResult<AdminResult[]>>({
    method: 'GET',
    url: '/admin/page',
    params
  })
}
/**
 * 启用、禁用管理员账号  query参数
 * @param status 
 * @param id 
 * @returns 
 */
export const postAdminStatusAPI = (status: number, id: number) => {
  return request({
    method: 'POST',
    url: `/admin/status/${status}`,
    params: { id }
  })
}
/**
 * 新增管理员 body参数
 * @param params 
 * @returns 
 */
export const addAdminAPI = (params: AdminData) => {
  return request({
    method: 'POST',
    url: '/admin',
    data: params
  })
}
/**
 * 根据id查询管理员
 * @param id 
 * @returns 
 */
export const getAdminAPI = (id: number) => {
  return request<AdminResult>({
    method: 'GET',
    url: `/admin/${id}`
  })
}
/**
 * 编辑管理员信息 Body参数
 * @param params 
 * @returns 
 */
export const putAdminAPI = (params: AdminData) => {
  return request({
    method: 'PUT',
    url: '/admin',
    data: params
  })
}
// 修改头像
export const putAdminAvatarAPI = (id: number, avatar: string) => {
  return request({
    method: 'PUT',
    url: '/admin/avatar',
    params: { id, avatar }
  })
}
/**
 * 修改密码
 */
interface pwdData {
  id: number
  oldPassword: string
  newPassword: string
}
export const putAdminPwdAPI = (params: pwdData) => {
  return request({
    method: 'PUT',
    url: '/admin/editPassword',
    data: params
  })
}